package atom.core0.bean.general;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


public class ValuePair implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private String code;
	private String desc;

	public String getCode()
	{
		return code;
	}
	public void setCode(String code)
	{
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public ValuePair(String code, String desc)
	{
		super();
		this.code = code;
		this.desc = desc;
	}
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("{");
		sb.append(this.code);
		sb.append(":");
		sb.append("\"");
		sb.append(this.desc);
		sb.append("\"");
		sb.append("}");
		
		return sb.toString();
	}	
	public boolean equals(ValuePair obj) {
		if (obj == null) {
			return false;
		}
		
		if (obj.getClass() != this.getClass()) {
			return false;
		}
		
		return this.code.equals( obj.getCode());
	}

	public int hashCode() {
		return this.getCode().hashCode();
	}	
	public static List getOrderedList(List<ValuePair> orderedList ) {
		Collections.sort(orderedList, new Comparator() {
			public int compare(Object o1, Object o2) {
				ValuePair type1 = (ValuePair) o1;
				ValuePair type2 = (ValuePair) o2;
				
				return type1.getCode().compareTo(type2.getCode());
			}
		});
		
		return orderedList;
	}
}